![]() |
PATH![]() |
![]() ![]() |
One technique that can be especially useful for debugging control statements is to use the Script Editor's Event Log window. You open the Event Log window from the Controls menu or by typing Command-E. The Event Log window displays diagnostic information while a script is running. This information can help you discover and correct errors by showing the results of the script's actions.
In addition to simply opening the Event Log to view the results of a script's actions, you can insert log statements at strategic locations in your script. A log statement reports the value of one or more variables to the Event Log window.
In the following script, the statement log currentWord is a debugging statement. It causes the current word to be displayed in the Script Editor's Event Log window each time through the loop. Log statements can be very helpful in testing a Repeat loop or other control statement. Once the loop is working correctly, you can comment out or delete any log statements.
set wordList to words in "Where is the hammer?"
repeat with currentWord in wordList
log currentWord
if currentWord as text is equal to "hammer" then
display dialog "I found the hammer!"
end if
end repeat
This script examines a list of words with the Repeat With (loopVariable) In (list) form of the Repeat statement, displaying a dialog if it finds the word "hammer" in the list. For more information, see Repeat With (loopVariable) In (list).
For basic debugging techniques and a detailed description of how to use the Event Log window, see Debugging Scripts. For additional information on the Script Editor's Event Log window, see the AppleScript section of the Mac OS Help Center.